#ifndef __Material_H__
#define __Material_H__

#include "d3dheaders.h"
#include "video/Texture.h"
#include <vector>

namespace KEngine
{

class TextureManager;
class Material
{
	typedef std::vector<Material*> SubMtlList;
	typedef std::vector<Material*>::iterator SubMtlIterator;	

public:
	Material();
	virtual ~Material();

	void			setAmbient(D3DCOLORVALUE& ambient);
	void			setDiffuse(D3DCOLORVALUE& diffuse);
	void			setSpecular(D3DCOLORVALUE& specular);
	void			setTexture(const char* filename,TextureManager* texturMgr);
	bool			addSubMtl(Material* mtl);

	D3DCOLORVALUE	getAmbient();
	D3DCOLORVALUE	getDiffuse();
	D3DCOLORVALUE	getSpecular();
	Texture*		getTexture();

	bool			hasSubMtl() { return !mSubMtls.empty(); }
	int				getSubNum() { return mSubMtls.size(); }
	Material*		getSubMtl(int i) { return mSubMtls[i]; }

	D3DMaterial*	getD3DMaterial();

protected:
	void			_needUpdate();
	void			_update();

protected:
	bool				mNeedUpdate;

	D3DCOLORVALUE		mAmbient;
	D3DCOLORVALUE		mDiffuse;
	D3DCOLORVALUE		mSpecular;
	D3DMaterial			mD3DMaterial;
	Texture*			mTexture;
	
	TextureManager*		mTexturMgr;
	SubMtlList			mSubMtls;
};

typedef std::vector<Material*> MaterialList;
typedef std::vector<Material*>::iterator MaterialIterator;

}
#endif 